@Typed package org.mbte.groovypp.examples.wordcount

for (i in 0..<10) {
    def t1 = System.currentTimeMillis()
    def counts = [:]
    new File("./20_newsgroups").eachFileRecurse{ f ->
      if (!f.isDirectory() && !f.path.contains(".svn")) {
      f.text.toLowerCase().eachMatch(/\w+/) { w ->
          def c = counts[w] ?: 0
          counts[w] = c + 1 } } }
    new File("counts-descreasing-groovy").withWriter { out ->
      counts.sort { a, b -> b.value <=> a.value }.each { k, v -> out << "$k\t$v\n" } }
    new File("counts-alphabetical-groovy").withWriter { out ->
      counts.sort { it.key }.each { k, v -> out << "$k\t$v\n" } }
    println "Finished in ${System.currentTimeMillis() - t1} millis"
}